package com.easy.frame.servers.sys.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.easy.frame.base.basic.pojo.vo.BaseTreeVO;
import com.easy.frame.servers.sys.dto.SysCategoryTypeDTO;
import com.easy.frame.servers.sys.entity.SysCategoryType;
import com.easy.frame.servers.sys.entity.SysEquipmentType;
import com.easy.frame.servers.sys.mapper.type.SysEquipmentTypeMapper;
import com.easy.frame.servers.sys.service.SysCategoryTypeService;
import com.easy.frame.servers.sys.service.SysEquipmentTypeService;
import com.easy.frame.servers.sys.vo.SysCategoryTypeVO;
import com.easy.frame.servers.sys.vo.SysEquipmentTypeVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * 设备设施分类表 服务实现类
 *
 * @author tp
 * @since 2020-12-24
 */
@Slf4j
@Service
public class SysEquipmentTypeServiceImpl extends ServiceImpl<SysEquipmentTypeMapper, SysEquipmentType> implements SysEquipmentTypeService {

    @Resource
    SysCategoryTypeService sysCategoryTypeService;

    /**
     * 获取数组织
     */
    @Override
    public BaseTreeVO getEquTypeTree(int enabled, String equName, String type) {
        return sysCategoryTypeService.getEquTypeTree(enabled, equName, type);
    }

    @Override
    public SysEquipmentTypeVO selectById(Long id) {
        SysCategoryTypeVO sysCategoryTypeVO = sysCategoryTypeService.selectById(id);
        SysEquipmentTypeVO sysEquipmentTypeVO = new SysEquipmentTypeVO();
        BeanUtils.copyProperties(sysCategoryTypeVO, sysEquipmentTypeVO);
        return sysEquipmentTypeVO;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public SysCategoryType add(SysCategoryTypeDTO addDTO) {
        return sysCategoryTypeService.add(addDTO);
    }

    /**
     * 根据id获取总数，但是条件是已启用和未删除
     */
    @Override
    public int countById(Long id) {
        return sysCategoryTypeService.countById(id);
    }

    /**
     * 点击添加返回给前端的封装数据
     */
    @Override
    public SysCategoryTypeVO clickAddEqu(Integer parentEquId, String type) {
        return sysCategoryTypeService.clickAddEqu( parentEquId, type);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateDelete(Long id) {
        sysCategoryTypeService.updateDelete(id);
    }


    @Override
    @Transactional(rollbackFor = Exception.class)
    public SysCategoryType modify(SysCategoryTypeDTO entity) {
        return sysCategoryTypeService.modify(entity);
    }

    @Override
    public void updateParentDelete(Long id) {
        sysCategoryTypeService.updateParentDelete(id);
    }
}
